package com.cskaoyan.exception;

import com.cskaoyan.vo.BaseRespVo;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * 该类中包含处理异常的@ExceptionHandler方法
 * @author stone
 * @date 2022/10/08 15:41
 */
//@ControllerAdvice
//@ResponseBody
@RestControllerAdvice
public class ExceptionControllerAdvice {

    // 方法的返回值：ModelAndView(ModelAndView\String)    Json
    // @ResponseBody
    /*@ExceptionHandler(ArithmeticException.class)
    public String arithmeticExceptionResolve() {
        return "/exception2.jsp";
    }*/

    @ExceptionHandler(ArithmeticException.class)
    //@ResponseBody
    public BaseRespVo arithmeticExceptionResolve(ArithmeticException exception) {
        String message = exception.getMessage();
        return BaseRespVo.fail(message);
    }
}
